/**
 * 作者: wgx
 * 日期: 2024-11-13 16:40:13
 * 备注: 用户派对的举办记录
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserFeastRecord;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserFeastRecordModel extends BaseModel implements Model {
    public static final String LISTKEY = "user_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // ID
    protected long userId; // 用户ID
    protected long feastId; // 宴会ID
    protected int feastMainId; // 派对类型id
    protected int guestNum; // 赴宴人数
    protected int score; // 派对人气
    protected long addTime; // 举办时间
    protected int isShow; // 客户端是否表现过 (1-表现过)
    protected long finishTime; // 派对的结束时间

    public void reset() {
    }

    protected String getKey() {
        return "UserFeastRecord." + id;
    }

    protected String getListKey() {
        return "UserFeastRecord." + userId;
    }

    protected String getListItemKey() {
        return id + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_feast_record"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // ID
        obj.put("userId", userId); // 用户ID
        obj.put("feastId", feastId); // 宴会ID
        obj.put("feastMainId", feastMainId); // 派对类型id
        obj.put("guestNum", guestNum); // 赴宴人数
        obj.put("score", score); // 派对人气
        obj.put("addTime", addTime); // 举办时间
        obj.put("isShow", isShow); // 客户端是否表现过 (1-表现过)
        obj.put("finishTime", finishTime); // 派对的结束时间
        return obj;
    }

    public PBUserFeastRecord.Builder takeInitBuilder() {
        PBUserFeastRecord.Builder sb = PBUserFeastRecord.newBuilder();
        if (feastId != 0) {
            sb.setFeastId(feastId);
        }
        if (feastMainId != 0) {
            sb.setFeastMainId(feastMainId);
        }
        if (guestNum != 0) {
            sb.setGuestNum(guestNum);
        }
        if (score != 0) {
            sb.setScore(score);
        }
        if (addTime != 0) {
            sb.setAddTime(addTime);
        }
        return sb;
    }

    public PBUserFeastRecord.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserFeastRecord.Builder sb = PBUserFeastRecord.newBuilder();
        if (isFieldUpdate("feastId")) {
            sb.setFeastId(feastId);
        }
        if (isFieldUpdate("feastMainId")) {
            sb.setFeastMainId(feastMainId);
        }
        if (isFieldUpdate("guestNum")) {
            sb.setGuestNum(guestNum);
        }
        if (isFieldUpdate("score")) {
            sb.setScore(score);
        }
        if (isFieldUpdate("addTime")) {
            sb.setAddTime(addTime);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public long getFeastId() {
        return feastId;
    }

    public void putFeastId(long feastId) {
        if (this.feastId != feastId) {
            this.feastId = feastId;
            updateRedisHashField(getKey(), "feastId", this.feastId);
        }
    }

    public void addFeastId(long value) {
        this.feastId += value;
        updateRedisHashField(getKey(), "feastId", this.feastId);
    }

    public int getFeastMainId() {
        return feastMainId;
    }

    public void putFeastMainId(int feastMainId) {
        if (this.feastMainId != feastMainId) {
            this.feastMainId = feastMainId;
            updateRedisHashField(getKey(), "feastMainId", this.feastMainId);
        }
    }

    public void addFeastMainId(int value) {
        this.feastMainId += value;
        updateRedisHashField(getKey(), "feastMainId", this.feastMainId);
    }

    public int getGuestNum() {
        return guestNum;
    }

    public void putGuestNum(int guestNum) {
        if (this.guestNum != guestNum) {
            this.guestNum = guestNum;
            updateRedisHashField(getKey(), "guestNum", this.guestNum);
        }
    }

    public void addGuestNum(int value) {
        this.guestNum += value;
        updateRedisHashField(getKey(), "guestNum", this.guestNum);
    }

    public int getScore() {
        return score;
    }

    public void putScore(int score) {
        if (this.score != score) {
            this.score = score;
            updateRedisHashField(getKey(), "score", this.score);
        }
    }

    public void addScore(int value) {
        this.score += value;
        updateRedisHashField(getKey(), "score", this.score);
    }

    public long getAddTime() {
        return addTime;
    }

    public void putAddTime(long addTime) {
        if (this.addTime != addTime) {
            this.addTime = addTime;
            updateRedisHashField(getKey(), "addTime", this.addTime);
        }
    }

    public void addAddTime(long value) {
        this.addTime += value;
        updateRedisHashField(getKey(), "addTime", this.addTime);
    }

    public int getIsShow() {
        return isShow;
    }

    public void putIsShow(int isShow) {
        if (this.isShow != isShow) {
            this.isShow = isShow;
            updateRedisHashField(getKey(), "isShow", this.isShow);
        }
    }

    public void addIsShow(int value) {
        this.isShow += value;
        updateRedisHashField(getKey(), "isShow", this.isShow);
    }

    public long getFinishTime() {
        return finishTime;
    }

    public void putFinishTime(long finishTime) {
        if (this.finishTime != finishTime) {
            this.finishTime = finishTime;
            updateRedisHashField(getKey(), "finishTime", this.finishTime);
        }
    }

    public void addFinishTime(long value) {
        this.finishTime += value;
        updateRedisHashField(getKey(), "finishTime", this.finishTime);
    }

}